ga.view.billard
Class BillardEvaluationState<T extends IAgeIndividual<T>>

java.lang.Object
  extended by com.jme3.app.state.AbstractAppState
      extended by ga.view.appstate.RootNodeState
          extended by ga.view.appstate.SceneState
              extended by ga.view.billard.BillardEvaluationState<T>
Type Parameters:
T - The generic type of the individuals.
All Implemented Interfaces:
com.jme3.app.state.AppState, IFitnessEvaluator<T>, IInteractiveFitnessEvaluator<T>, IMenuListenerParent

public class BillardEvaluationState<T extends IAgeIndividual<T>>
extends SceneState
implements IInteractiveFitnessEvaluator<T>, IMenuListenerParent

This interactive evaluator is a special case for direct selection.

Since:
12.08.2012
Author:
Stephan Dreyer

Nested Class Summary
private  class BillardEvaluationState.CenteringListener
          Key listener to toggle centering behavior.
private  class BillardEvaluationState.ClickListener
          Mouse listener to recognize clicks on objects.
private  class BillardEvaluationState.DebugListener
          Key listener to toggle debug display.
private  class BillardEvaluationState.PausedListener
          Key listener to toggle pause.
 
Field Summary
private  ISIGA<T> algorithm
           
private  com.jme3.bullet.BulletAppState bulletAppState
           
private  boolean debug
           
private  BillardEvaluationState.ClickListener dragListener
           
private  IIndividualFactory<T> factory
           
private  java.util.List<EvaluationListener<T>> listeners
           
private static java.util.logging.Logger LOGGER
           
private  MenuListener menuListener
           
private  java.util.Map<T,BillardObjectNode<T>> nodeMap
           
private  com.jme3.scene.Node objectsNode
           
private  boolean paused
           
private  IPhenotypeGenerator<T,com.jme3.scene.Geometry> phenotypeGenerator
           
private  float scale
           
private  float sceneHeight
           
private  float sceneWidth
           
private  boolean useCentering
           
private  float wallHeight
           
private  float wallThickness
           
 
Fields inherited from class ga.view.appstate.SceneState
app, assetManager, cam, inputManager, renderManager, stateManager, timer, viewPort
 
Fields inherited from class ga.view.appstate.RootNodeState
rootNode
 
Fields inherited from class com.jme3.app.state.AbstractAppState
initialized
 
Constructor Summary
BillardEvaluationState(IIndividualFactory<T> factory, IPhenotypeGenerator<T,com.jme3.scene.Geometry> phenotypeGenerator)
          Instantiates a new billard evaluation state.
 
Method Summary
 void addEvaluationListener(EvaluationListener<T> listener)
          Adds an EvaluationListener that will be notified about the evaluation state.
private  void addRandomObject(float x, float z)
          Creates a random object and places it at x,y on the table.
 void cleanup()
           
 void evaluate(T individual)
          Evaluates the given individual.
private  com.jme3.collision.CollisionResults findPick(com.jme3.scene.Node node)
          Finds spatials in the scene that has been clicked.
 void fireIndividualEvaluated(T individual)
          Notification method that causes all EvaluationListeners being notified that the evaluator has evaluated the individual.
 void fireNewIndividualRequested()
          Notification method that causes all EvaluationListeners being notified that the evaluator demands a new individual for evaluation.
 ISIGA<T> getAlgorithm()
          Getter for the interactive genetic algorithm.
private  com.jme3.bullet.PhysicsSpace getPhysicsSpace()
          Getter for the physics space.
private  void initCam()
          Inits the camera.
 void initialize(com.jme3.app.state.AppStateManager stateManager, com.jme3.app.Application app)
           
private  void initObjects()
          Inits the objects on the table.
private  void initTable()
          Make a solid floor and add it to the scene.
 void removeEvaluationListener(EvaluationListener<T> listener)
          Adds an EvaluationListener.
 void setAlgorithm(ISIGA<T> siga)
          Sets the interactive genetic algorithm.
 void setEnabled(boolean enabled)
           
 void setMenuListener(MenuListener menuListener)
          Sets the menu listener.
 void setPaused(boolean paused)
          Pauses the rendering and physics calculation.
 void update(float tpf)
           
 
Methods inherited from class ga.view.appstate.SceneState
finalCleanUp, getCamera
 
Methods inherited from class ga.view.appstate.RootNodeState
getRootNode
 
Methods inherited from class com.jme3.app.state.AbstractAppState
isEnabled, isInitialized, postRender, render, stateAttached, stateDetached
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

objectsNode

private com.jme3.scene.Node objectsNode

bulletAppState

private final com.jme3.bullet.BulletAppState bulletAppState

dragListener

private BillardEvaluationState.ClickListener dragListener

scale

private final float scale
See Also:
Constant Field Values

sceneHeight

private final float sceneHeight
See Also:
Constant Field Values

sceneWidth

private float sceneWidth

wallHeight

private final float wallHeight
See Also:
Constant Field Values

wallThickness

private final float wallThickness
See Also:
Constant Field Values

algorithm

private ISIGA<T extends IAgeIndividual<T>> algorithm

phenotypeGenerator

private final IPhenotypeGenerator<T extends IAgeIndividual<T>,com.jme3.scene.Geometry> phenotypeGenerator

factory

private final IIndividualFactory<T extends IAgeIndividual<T>> factory

menuListener

private MenuListener menuListener

listeners

private final java.util.List<EvaluationListener<T extends IAgeIndividual<T>>> listeners

nodeMap

private final java.util.Map<T extends IAgeIndividual<T>,BillardObjectNode<T extends IAgeIndividual<T>>> nodeMap

paused

private boolean paused

useCentering

private boolean useCentering

debug

private boolean debug
Constructor Detail

BillardEvaluationState

public BillardEvaluationState(IIndividualFactory<T> factory,
                              IPhenotypeGenerator<T,com.jme3.scene.Geometry> phenotypeGenerator)
Instantiates a new billard evaluation state.

Parameters:
factory - the factory
phenotypeGenerator - the phenotype generator
Since:
12.08.2012
Method Detail

initialize

public void initialize(com.jme3.app.state.AppStateManager stateManager,
                       com.jme3.app.Application app)
Specified by:
initialize in interface com.jme3.app.state.AppState
Overrides:
initialize in class SceneState

cleanup

public void cleanup()
Specified by:
cleanup in interface com.jme3.app.state.AppState
Overrides:
cleanup in class RootNodeState

setEnabled

public void setEnabled(boolean enabled)
Specified by:
setEnabled in interface com.jme3.app.state.AppState
Overrides:
setEnabled in class SceneState

update

public void update(float tpf)
Specified by:
update in interface com.jme3.app.state.AppState
Overrides:
update in class RootNodeState

setPaused

public void setPaused(boolean paused)
Pauses the rendering and physics calculation.

Parameters:
paused - the new paused flag.
Since:
12.08.2012

setAlgorithm

public void setAlgorithm(ISIGA<T> siga)
Description copied from interface: IInteractiveFitnessEvaluator
Sets the interactive genetic algorithm.

Specified by:
setAlgorithm in interface IInteractiveFitnessEvaluator<T extends IAgeIndividual<T>>
Parameters:
siga - The SIGA.

getAlgorithm

public ISIGA<T> getAlgorithm()
Description copied from interface: IInteractiveFitnessEvaluator
Getter for the interactive genetic algorithm.

Specified by:
getAlgorithm in interface IInteractiveFitnessEvaluator<T extends IAgeIndividual<T>>
Returns:
The SIGA.

initCam

private void initCam()
Inits the camera.

Since:
12.08.2012

initTable

private void initTable()
Make a solid floor and add it to the scene.


initObjects

private void initObjects()
Inits the objects on the table.

Since:
12.08.2012

addRandomObject

private void addRandomObject(float x,
                             float z)
Creates a random object and places it at x,y on the table.

Parameters:
x - The x location.
z - The y location.
Since:
12.08.2012

findPick

private com.jme3.collision.CollisionResults findPick(com.jme3.scene.Node node)
Finds spatials in the scene that has been clicked.

Parameters:
node - The parent node to check for clicks.
Returns:
The results of the click.
Since:
12.08.2012

getPhysicsSpace

private com.jme3.bullet.PhysicsSpace getPhysicsSpace()
Getter for the physics space.

Returns:
The physics space.
Since:
12.08.2012

fireNewIndividualRequested

public void fireNewIndividualRequested()
Description copied from interface: IInteractiveFitnessEvaluator
Notification method that causes all EvaluationListeners being notified that the evaluator demands a new individual for evaluation.

Specified by:
fireNewIndividualRequested in interface IInteractiveFitnessEvaluator<T extends IAgeIndividual<T>>

fireIndividualEvaluated

public void fireIndividualEvaluated(T individual)
Description copied from interface: IInteractiveFitnessEvaluator
Notification method that causes all EvaluationListeners being notified that the evaluator has evaluated the individual.

Specified by:
fireIndividualEvaluated in interface IInteractiveFitnessEvaluator<T extends IAgeIndividual<T>>
Parameters:
individual - The evaluated individual.

addEvaluationListener

public void addEvaluationListener(EvaluationListener<T> listener)
Description copied from interface: IInteractiveFitnessEvaluator
Adds an EvaluationListener that will be notified about the evaluation state.

Specified by:
addEvaluationListener in interface IInteractiveFitnessEvaluator<T extends IAgeIndividual<T>>
Parameters:
listener - The listener.

removeEvaluationListener

public void removeEvaluationListener(EvaluationListener<T> listener)
Description copied from interface: IInteractiveFitnessEvaluator
Adds an EvaluationListener.

Specified by:
removeEvaluationListener in interface IInteractiveFitnessEvaluator<T extends IAgeIndividual<T>>
Parameters:
listener - The listener.

evaluate

public void evaluate(T individual)
Description copied from interface: IFitnessEvaluator
Evaluates the given individual.

Specified by:
evaluate in interface IFitnessEvaluator<T extends IAgeIndividual<T>>
Specified by:
evaluate in interface IInteractiveFitnessEvaluator<T extends IAgeIndividual<T>>
Parameters:
individual - Individual to evaluate.

setMenuListener

public void setMenuListener(MenuListener menuListener)
Description copied from interface: IMenuListenerParent
Sets the menu listener.

Specified by:
setMenuListener in interface IMenuListenerParent
Parameters:
menuListener - the new menu listener